package com.scisoft.scan.control.enterdepot;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.scisoft.scan.data.enterdepot.EnterDepotOrderDetailBean;
import com.scisoft.scan.dy.R;
import com.squareup.picasso.Picasso;

import java.util.List;

public class EnterDepotDetailAdapter extends BaseAdapter {
    private List<EnterDepotOrderDetailBean> depotOrderDetailBeanList;//数据源
    private LayoutInflater mInflater;//布局装载器对象
    private Context mContext;

    public EnterDepotDetailAdapter(List<EnterDepotOrderDetailBean> depotOrderDetailBeanList, Context context) {
        this.depotOrderDetailBeanList = depotOrderDetailBeanList;
        mInflater = LayoutInflater.from(context);
        mContext = context;
    }

    @Override
    public int getCount() {
        //return返回的是int类型，也就是页面要显示的数量。
        return depotOrderDetailBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return depotOrderDetailBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_enterdepotorderdetail, null);
        }
        //数量
        TextView tv_partCount = convertView.findViewById(R.id.tv_partCount);
        //已拣
        TextView tv_doneCount = convertView.findViewById(R.id.tv_doneCount);
        //待拣
        TextView tv_todoCount = convertView.findViewById(R.id.tv_todoCount);
        //待拣文字
        TextView tv_todoCountTitle = convertView.findViewById(R.id.tv_todoCountTitle);
        //完成
        TextView tv_ok = convertView.findViewById(R.id.tv_ok);
        //图片
        ImageView iv_img = convertView.findViewById(R.id.iv_img);
        //配件信息
        TextView tv_partInfo = convertView.findViewById(R.id.tv_partInfo);
        //供应商信息
        TextView tv_supplierInfo = convertView.findViewById(R.id.tv_supplierInfo);

        //获取相应索引的ItemBean对象
        EnterDepotOrderDetailBean bean = depotOrderDetailBeanList.get(position);
        //设置控件的对应属性值
        tv_partCount.setText(String.valueOf(bean.partCount));
        tv_doneCount.setText(String.valueOf(bean.pickedCount));
        tv_todoCount.setText(String.valueOf(bean.notPickedCount));
        tv_partInfo.setText(bean.partCode + " " + bean.partName);
        tv_supplierInfo.setText(bean.supplierCode + " " + bean.supplierName);

        if (bean.ifOk.equals("1")) {
            tv_ok.setVisibility(View.VISIBLE);
            tv_todoCount.setVisibility(View.GONE);
            tv_todoCountTitle.setVisibility(View.GONE);
        } else {
            tv_ok.setVisibility(View.GONE);
            tv_todoCount.setVisibility(View.VISIBLE);
            tv_todoCountTitle.setVisibility(View.VISIBLE);
        }

        if (bean.imgUrl != null && !bean.imgUrl.equals("")) {
            Picasso.with(mContext).load(bean.imgUrl).into(iv_img);
        } else {
            iv_img.setImageDrawable(convertView.getResources().getDrawable(R.drawable.ic_noimage));
        }
        return convertView;
    }
}
